//类的语法
class Personxx {
  name: string;
  age: number;
  constructor(a: string, b: number) {
    this.name = a;
    this.age = b;
  }
  speak() {
    console.log(`我的名字${this.name},今年${this.age}`);
  }
}

const p1 = new Personxx("张三", 40);
console.log(p1);
p1.speak();

//类的继承与TS语法
class Student extends Personxx {
  school: string;
  constructor(a: string, b: number, c: string) {
    super(a, b);
    this.school = c;
  }
  study() {
    console.log(`我的名字${this.name},今年${this.age}，正在学习`);
  }
  override speak() {
    //重写从父类继承的方法
    //override为了ts检测名字是否对，覆盖父类的方法
    console.log(`我是学生，我的名字${this.name},今年${this.age}`);
  }
}
const s1 = new Student("小王", 25, "上海大学");
console.log(s1);
s1.study();
s1.speak();
